<?php
    @include_once("general.php");
    $goodsId=isset($_GET["goodsId"])?$_GET["goodsId"]:0;
    $userName=isset($_GET["userName"])?$_GET["userName"]:0;
    $sqlStr;
    if($userName&&$goodsId){
        global $sqlStr;
        //判断该用户购物车是否存在id名为goodsid的商品，如果有就在原来基础上增加1，如果没有就插入一条数据
        $sqlStr="SELECT * from shopping_car where userName='$userName' and goods_id='$goodsId'";
        if(query($sqlStr)){
            //有数据时增加数量
            $sqlStr="UPDATE shopping_car SET number=number+1 WHERE userName='$userName' and goods_id='$goodsId'";
            echo json_encode(change($sqlStr));
        }else{
            //没有数据时，插入一条数据
            $sqlStr="INSERT into shopping_car(userName,goods_id,number) VALUES('$userName','$goodsId',1) ";
            echo json_encode(change($sqlStr));
        }
    }
?>